package com.zero.mxshengadmin.modules.website.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zero.mxshengadmin.common.exception.RRException;
import com.zero.mxshengadmin.common.utils.PageUtils;
import com.zero.mxshengadmin.common.utils.Query;
import com.zero.mxshengadmin.modules.website.dao.WebsiteQuestionDao;
import com.zero.mxshengadmin.modules.website.entity.WebsiteQuestionEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteQuestionService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by aicaikeji on 2019/4/3.
 */
@Service("websiteQuestionService")
public class WebsiteQuestionServiceImpl extends ServiceImpl<WebsiteQuestionDao,WebsiteQuestionEntity> implements WebsiteQuestionService {

    /**
     * 添加问题
     * @param entity
     * @return
     */
    @Override
    public void save(WebsiteQuestionEntity entity) {
        boolean save = this.insert(entity);
        if (!save) throw new RRException("操作失败");
    }


    /**
     * 查询问题
     * @param id
     * @return
     */
    @Override
    public WebsiteQuestionEntity getById(long id) {
        return this.selectById(id);
    }


    /**
     * 删除问题信息
     * @param ids
     * @return
     */
    @Override
    public void removeByIds(Long[] ids) {
        this.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<WebsiteQuestionEntity> page = this.selectPage(
                new Query<WebsiteQuestionEntity>(params).getPage(),
                new EntityWrapper<>()
        );
        return new PageUtils(page);
    }
}
